package cn.sql_session;

import org.apache.ibatis.logging.Log;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;


public class SqlSessionBuild {


    private final Class<? extends Log> logImpl;


    private final Configuration configuration;

    public SqlSessionBuild(Configuration configuration) {
        this.logImpl = org.apache.ibatis.logging.nologging.NoLoggingImpl.class;
        this.configuration = configuration;
        configuration.setLogImpl(logImpl);
    }

    public SqlSessionBuild(Class<? extends Log> logImpl, Configuration configuration) {
        this.logImpl = logImpl;
        this.configuration = configuration;
        configuration.setLogImpl(logImpl);
    }


    private SqlSession getSqlSession() {
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
        return sqlSessionFactory.openSession();
    }


}
